package com.hospital.hospitalworkservice.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.hospitalworkservice.entity.Vipperson;
import com.hospital.hospitalworkservice.mapper.VippersonMapper;
import com.hospital.hospitalworkservice.service.IVippersonService;
import com.hospital.hospitalworkservice.utils.ExcelBean;
import com.hospital.hospitalworkservice.utils.ExcelUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author dwl
 * @since 2020-10-21
 */
@Slf4j
@Service
public class VippersonServiceImpl extends ServiceImpl<VippersonMapper, Vipperson> implements IVippersonService {


    @Override
    public IPage<Vipperson> selectPageVo(Page page, Vipperson vo) {

        return baseMapper.selectPageVo(page, vo);
    }


    @Override
    public XSSFWorkbook daochu() throws IllegalAccessException, Exception, ClassNotFoundException {
        List<Vipperson> list = baseMapper.download();
        log.info(list+"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        Map<Integer,List<ExcelBean>> map=new HashMap<>();
        Class<Vipperson> userClass = Vipperson.class;
        Field[] declaredFields = userClass.getDeclaredFields();
        List<ExcelBean> excelBeans=new ArrayList<>();

        excelBeans.add(new ExcelBean("id",declaredFields[0].getName(),0));
        excelBeans.add(new ExcelBean("卡号",declaredFields[1].getName(),0));
//        excelBeans.add(new ExcelBean("会员等级",declaredFields[2].getName(),0));
        excelBeans.add(new ExcelBean("会员名称",declaredFields[10].getName(),0));
        excelBeans.add(new ExcelBean("累计消费",declaredFields[3].getName(),0));
        excelBeans.add(new ExcelBean("存储余额",declaredFields[4].getName(),0));
        excelBeans.add(new ExcelBean("累计余额",declaredFields[5].getName(),0));
        excelBeans.add(new ExcelBean("积分",declaredFields[6].getName(),0));
        excelBeans.add(new ExcelBean("开卡时间",declaredFields[7].getName(),0));
        excelBeans.add(new ExcelBean("过期时间",declaredFields[8].getName(),0));
        excelBeans.add(new ExcelBean("状态",declaredFields[9].getName(),0));
        map.put(0,excelBeans);
        return ExcelUtils.createExcelFile(Vipperson.class,list,map,"会员表");
    }
}
